package org.jasig.services.persondir.support;

import org.jasig.services.persondir.IPersonAttributes;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/9/13.
 */
public class AccoutAttributeDao extends StubPersonAttributeDao {
    private JdbcTemplate myjdbcTemplate;
    public JdbcTemplate getMyjdbcTemplate() {
        return myjdbcTemplate;
    }
    public void setMyjdbcTemplate(JdbcTemplate myjdbcTemplate) {
        this.myjdbcTemplate = myjdbcTemplate;
    }

    @Override
    public IPersonAttributes getPerson(String userid) {
        String sql = "";
        final Map<String, Object> values;
        sql = "SELECT * FROM `user` where username=? and `status`=1";
        values = myjdbcTemplate.queryForMap(sql, userid);
        Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
        attributes.put("username",
                Collections.singletonList((Object) values.get("username")));
        return new AttributeNamedPersonImpl(attributes);
    }
}
























